package com.example.demo.controller;

import com.example.demo.entity.Laboratory;
import com.example.demo.entity.User;
import com.example.demo.mapper.LaboratoryMapper;
import com.example.demo.service.LaboratoryService;
import com.example.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/laboratory")
public class LaboratoryController {
    @Autowired
    private LaboratoryService laboratoryService;


    @PostMapping("/list")
    public List<Laboratory> list(@RequestBody Laboratory laboratory){
        return laboratoryService.list(laboratory);
    }

    @PostMapping("/save")
    public int save(@RequestBody  Laboratory laboratory){

        return laboratoryService.save(laboratory);
    }

    @PostMapping("/update")
    public int update(@RequestBody  Laboratory laboratory){
        if(laboratory.getId()==null){
            return 0;
        }
        return laboratoryService.update(laboratory);
    }


    @PostMapping("/delete")
    public int delete(@RequestBody  Laboratory laboratory){
        if(laboratory.getId()==null){
            return 0;
        }
        return laboratoryService.delete(laboratory.getId());
    }


    @PostMapping("/getById")
    public Laboratory getById(@RequestBody  Laboratory laboratory){
        if(laboratory.getId()==null){
            return null;
        }
        return laboratoryService.getById(laboratory.getId());
    }
}
